function a(a, t, i) {
    return t in a ? Object.defineProperty(a, t, {
        value: i,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : a[t] = i, a;
}

var t = getApp(), i = t.http.save_jiandangPost, n = t.http.timeduanPost;
var util = getApp().util
Page({
    data: {
        newdata: [{}],
        timeduan: [ "00:00-01:00", "01:00-02:00", "02:00-03:00", "03:00-04:00", "04:00-05:00" ],
        minuteData: [
          {
            name: "5分钟",
            value: 5
          },
          {
            name: "10分钟",
            value: 10
          },
          {
            name: "15分钟",
            value: 15
          },
          {
            name: "20分钟",
            value: 20
          },
          {
            name: "25分钟",
            value: 25
          },
          {
            name: "30分钟",
            value: 30
          },
          {
            name: "35分钟",
            value: 35
          } ],
        paimai_num: 7,
        guding_num: 3,
        minuteData_index: 2,
        selectIndex: 0,
        shousu_num:0,
        submit: 0
    },
    onLoad: function(a) {
      let systemInfoSync = wx.getSystemInfoSync();
      //rpx
      let windowheight = systemInfoSync.windowHeight * (750 / systemInfoSync.windowWidth)
      let safeAreaBottom = (systemInfoSync.screenHeight - systemInfoSync.safeArea.bottom) * (750 / systemInfoSync.windowWidth)
      this.setData({
          riqi: a.riqi.split(","),
          safeAreaBottom
      });
      wx.hideShareMenu({});//禁止分享
    },
    onReady: function() {},
    onShow: function() {
        this.timeduan();
        this.jiandangsubmit()
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    choise_time: function(a) {
        var t = a.currentTarget.dataset.index, i = this.data.selectIndex;
        this.setData({
            newdata_index: t
        });
        var n = this.selectComponent("#bottomDialog"), e = this.data.timeduan;
        n.setData({
            title: "上档时间",
            modelType: "timeduan",
            selectArray: e,
            selectIndex: i,
            hideFlag: !1
        }), n.showModal();
    },
    timeduanSure: function(t) {
        console.log(t);
        var i, n = t.detail.index, e = this.data.newdata, s = 1
        for (var o = 0; o < e.length; o++) {
            if (e[o].dangtime !=undefined && e[o].dangtime == this.data.timeduan[n]) {
              return void wx.showToast({
                title: "上档时间不能重复",
                image: "/image/icon_gantanhao.png",
                mask: !0
              });
              return;
            }
            "{}" != e[o] && o != n && (void 0 !== e[o].zhuchi && void 0 !== e[o].dangtime || (s = 0));
        }
        // void 0 === e[n].zhuchi && (s = 0);
        var d = "newdata[" + this.data.newdata_index + "].dangtime";
        this.setData((i = {}, a(i, d, this.data.timeduan[n]), a(i, "selectIndex", n), a(i, "submit", s), 
        i));
        this.jiandangsubmit()
    },
    choise_host: function(a) {
        var t = a.currentTarget.dataset.index;
        this.setData({
            newdata_index: t
        }), wx.navigateTo({
            url: "../xcx_host/xcx_host"
        });
    },
    newjian: function() {
        var a = this.data.newdata;
        a.push("{}"), this.setData({
            newdata: a
        });
    },
    choise_mintes: function() {
        var a = this.selectComponent("#bottomDialog"), t = this.data.minuteData;
        a.setData({
            title: "请选择",
            modelType: "select",
            selectArray: t,
            selectIndex: [ 1 ],
            hideFlag: !1
        }), a.showModal();
    },
    mintuesSure: function(a) {
        var t = a.detail.index;
        this.setData({
            minuteData_index: t
        });
    },
    paiwei_jian: function() {
        this.data.paimai_num - 1 >= 1 && this.setData({
            paimai_num: this.data.paimai_num - 1
        });
    },
    paiwei_jia: function() {
        this.setData({
            paimai_num: Number(this.data.paimai_num) + 1
        });
    },
    guding_jian: function() {
        this.data.guding_num - 1 >= 0 && this.setData({
            guding_num: this.data.guding_num - 1
        });
    },
    guding_jia: function() {
       this.data.shousu_num + this.data.guding_num < this.data.paimai_num ? this.setData({
            guding_num: Number(this.data.guding_num) + 1
        }) : wx.showToast({
            title: "不能大于排麦位",
            icon: "none",
            duration: 2e3
        });
    },
  shousu_jian: function () {
    this.data.shousu_num - 1 >= 0 && this.setData({
      shousu_num: this.data.shousu_num - 1
    });
  },
  shousu_jia: function () {
    this.data.shousu_num + this.data.guding_num< this.data.paimai_num ? this.setData({
      shousu_num: Number(this.data.shousu_num) + 1
    }) : wx.showToast({
      title: "不能大于排麦位",
      icon: "none",
      duration: 2e3
    });
  },
  //判断是否可以提交
  jiandangsubmit(){
    var a = this.data.newdata;
    var sumbit = 1;
    if ("[{}]" != a) {
      for (var t = 0; t < a.length; t++) {
        if ("{}" != a[t]) {
          if (!a[t].hasOwnProperty("dangtime")) {
            sumbit = 0;
          }
          if (!a[t].hasOwnProperty("zhuchi")) {
            sumbit = 0;
          }
        }
      }
    }else{
      sumbit = 0;
    }  
    this.setData({
      submit: sumbit
    })
  },
  save_jiandan: function() {
        var a = this.data.newdata;
        if ("[{}]" != a) {
            for (var t = 0; t < a.length; t++) if ("{}" != a[t]) {
                if (!a[t].hasOwnProperty("dangtime")) return void wx.showToast({
                    title: "请选择上档时间",
                    image: "/image/icon_gantanhao.png",
                    mask: !0
                });
                if (!a[t].hasOwnProperty("zhuchi")) return void wx.showToast({
                    title: "请选择主持",
                    image: "/image/icon_gantanhao.png",
                    mask: !0
                });
            } else a.splice(t, 1);
            if (this.data.paimai_num < this.data.guding_num) wx.showToast({
                title: "排麦位大于固定位",
                image: "/image/icon_gantanhao.png",
                mask: !0
            }); else if (null != this.data.minuteData_index) {
                var n = this.data.minuteData_index;
                i({
                    token: wx.getStorageSync("userinfo").token,
                    riqi: this.data.riqi.join("-"),
                    jiandang: JSON.stringify(a),
                    paimai: this.data.paimai_num,
                    gudingmai: this.data.guding_num,
                    ssp_num: this.data.shousu_num,
                    tiqian: this.data.minuteData[n].value,
                    hall_id: wx.getStorageSync("hall_info").id
                }).then(function(a) {
                    0 == a.code ? wx.showToast({
                        title: "建档成功",
                        icon: "success",
                        mask: !0,
                        success: function() {
                            wx.navigateBack({
                                delta: 1
                            });
                        }
                    }) : (wx.showToast({
                        title: "添加失败",
                        icon: "none",
                        mask: !0,
                        success: function() {}
                    }), console.log("接口返回数据失败", a));
                });
            } else wx.showToast({
                title: "请选择提前排麦时长",
                image: "/image/icon_gantanhao.png",
                mask: !0
            });
        } else wx.showToast({
            title: "请选择上档时间",
            image: "/image/icon_gantanhao.png",
            mask: !0
        });
    },
    timeduan: function() {
        var a = this, t = wx.getStorageSync("userinfo").token, i = this.data.riqi.join("-");
        var hall_id = wx.getStorageSync("hall_info").id
        n({
            token: t,
            hall_id:hall_id,
            riqi: i
        }).then(function(t) {
            0 == t.code ? a.setData({
                timeduan: t.data
            }) : console.log("接口返回数据失败", t);
        });
    }
});